# -*- coding: UTF-8 -*-
#启动时间测试
from socket import *
import threading
import time
import GetMsg

tcp_socket1 = socket(AF_INET,SOCK_STREAM)
tcp_socket1.connect(('127.0.0.1',21001))
tcp_socket2 = socket(AF_INET,SOCK_STREAM)
tcp_socket2.connect(('127.0.0.1',24000))

def radio():
	print("3")
	t1 = 0
	t2 = 0
	while(1):
		recv_data1 = tcp_socket1.recv(1024)
		recv_data1 = recv_data1.decode('utf-8')
		str = recv_data1.split("#")
		if "ApiName=onStartChlTest" == str[1]:
			t1 = time.time()
		if "ApiName=onRTDataVer1" == str[1]:
			t2 = time.time()
			print(t2 - t1,"s")
			t1 = 0
			t2 = 0

def main():
	print("2")
	send_data1 = GetMsg.GetStartMsg()#"000000721001110011#dev_no=1#chl_no=3#oper_flag=1#step_file=E:\\\\Documents\\\\cd.stp"
	print(send_data1)
	send_data1 = send_data1.encode('utf-8')
	send_data2 = GetMsg.GetStopMsg()#"000000401001110021#dev_no=1#chl_no=3#oper_flag=1"
	print(send_data2)
	send_data2 = send_data2.encode('utf-8')
	thread_radio = threading.Thread(target=radio)
	thread_radio.start()
	while(1):
		tcp_socket2.send(send_data1)
		tcp_socket2.recv(1024)
		time.sleep(3)
		tcp_socket2.send(send_data2)
		tcp_socket2.recv(1024)
		time.sleep(3)
	thread_radio.join()

main()
print("5")
tcp_socket1.close()
tcp_socket2.close()